package com.ruoyi.monitor.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.message.domain.Message;
import com.ruoyi.message.service.IMessageService;
import com.ruoyi.monitor.domain.Monitor;
import com.ruoyi.monitor.mapper.MonitorMapper;
import com.ruoyi.monitor.service.IMonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 班级监控Service业务层处理
 *
 * @author ruoyi
 * @date 2024-11-01
 */
@Service
public class MonitorServiceImpl implements IMonitorService {
    @Autowired
    private MonitorMapper monitorMapper;
    @Autowired
    private IMessageService messageService;

    /**
     * 查询班级监控
     *
     * @param id 班级监控主键
     * @return 班级监控
     */
    @Override
    public Monitor selectMonitorById(Long id) {
        return monitorMapper.selectMonitorById(id);
    }

    /**
     * 查询班级监控列表
     *
     * @param monitor 班级监控
     * @return 班级监控
     */
    @Override
    public List<Monitor> selectMonitorList(Monitor monitor) {
        return monitorMapper.selectMonitorList(monitor);
    }

    /**
     * 新增班级监控
     *
     * @param monitor 班级监控
     * @return 结果
     */
    @Override
    public int insertMonitor(Monitor monitor) {
        monitor.setCreateTime(DateUtils.getNowDate());
        return monitorMapper.insertMonitor(monitor);
    }

    /**
     * 修改班级监控
     *
     * @param monitor 班级监控
     * @return 结果
     */
    @Override
    public int updateMonitor(Monitor monitor) {
        monitor.setUpdateTime(DateUtils.getNowDate());
        return monitorMapper.updateMonitor(monitor);
    }

    /**
     * 批量删除班级监控
     *
     * @param ids 需要删除的班级监控主键
     * @return 结果
     */
    @Override
    public int deleteMonitorByIds(Long[] ids) {
        return monitorMapper.deleteMonitorByIds(ids);
    }

    /**
     * 删除班级监控信息
     *
     * @param id 班级监控主键
     * @return 结果
     */
    @Override
    public int deleteMonitorById(Long id) {
        return monitorMapper.deleteMonitorById(id);
    }

    /**
     * 监控报修
     *
     * @param monitor
     * @return
     */
    @Override
    public int repair(Monitor monitor) {
        Message message = new Message();
        message.setType("fix");
        message.setContent(monitor.getSchoolName() + " " + monitor.getClassName() + " 监控设备 " + monitor.getMonitorName() + " 损坏，请尽快处理！");
        message.setSendTime(DateUtils.getNowDate());
        return messageService.insertMessage(message);
    }
}
